home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 3: Developer Tools / Linux Cubed Series 3 - Developer Tools.iso / utils / console / svgatext.3 / svgatext / SVGATextMode-1.3 / vga_prg.h < prev    next >
Encoding:
C/C++ Source or Header  |  1996-02-11  |  8.7 KB  |  232 lines

  1. /*  SVGATextMode -- An SVGA textmode manipulation/enhancement tool
  2.  *
  3.  *  Copyright (C) 1995,1996  Koen Gadeyne
  4.  *
  5.  *  This program is free software; you can redistribute it and/or modify
  6.  *  it under the terms of the GNU General Public License as published by
  7.  *  the Free Software Foundation; either version 2 of the License, or
  8.  *  (at your option) any later version.
  9.  *
  10.  *  This program is distributed in the hope that it will be useful,
  11.  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  12.  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13.  *  GNU General Public License for more details.
  14.  *
  15.  *  You should have received a copy of the GNU General Public License
  16.  *  along with this program; if not, write to the Free Software
  17.  *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  18.  */
  19.  
  20.  
  21. /***
  22.  *** VGA chip programming functions for SVGATextMode
  23.  ***/
  24.  
  25. #ifndef _VGA_PRG_H
  26. #define _VGA_PRG_H
  27.  
  28. #include "misc.h"
  29.  
  30. extern int vgaIOBase;
  31. extern bool vga_open;
  32.  
  33. #include "chipset.h"
  34.  
  35. #ifndef DOS
  36. # include <asm/io.h>
  37. #else
  38. # ifdef DJGPP
  39. #    include <pc.h>
  40. #    define outb(data,port) outportb(port,data)
  41. #    define outw(data,port) outportw(port,data)
  42. #    define inb(port) inportb(port)
  43. #    define inw(port) inportw(port)
  44. #  else /* Borland C */
  45. #    define outb(data,port) outp(port,data)
  46. #    define outw(data,port) outpw(port,data)
  47. #    define inb(port) inp(port)
  48. #    define inw(port) inpw(port)
  49. #  endif
  50. #  define ioperm(x,y,z) (0)
  51. #endif
  52.  
  53. /*
  54.  * Some important VGA registers
  55.  */
  56.  
  57. #define SEQ_INDEX    0x3C4
  58. #define SEQ_DATA    (SEQ_INDEX+1)
  59. #define CRTC_INDEX    (vgaIOBase+0x04)
  60. #define CRTC_DATA    (CRTC_INDEX+1)
  61. #define VGA_MISC_R    0x3CC
  62. #define VGA_MISC_W    0x3C2
  63. #define VGA_FEAT_R    0x3CA
  64. #define VGA_FEAT_W    (vgaIOBase+0x0A)
  65. #define GR_CTL_INDEX    0x3CE
  66. #define GR_CTL_DATA    (GR_CTL_INDEX+1)
  67. #define ATR_CTL_INDEX    0x3C0
  68. #define ATR_CTL_DATA_W    (ATR_CTL_INDEX)
  69. #define ATR_CTL_DATA_R    (ATR_CTL_INDEX+1)
  70. #define STATUS1        (vgaIOBase+0x0A)
  71. #define STATUS0        0x3C2
  72. #define ATR_CTL_INDEX_DATA_SWITCH  STATUS1
  73. #define DAC_MASK        0x3C6
  74. #define DAC_STATUS    0x3C7
  75. #define DAC_RD_INDEX    0x3C7
  76. #define DAC_WR_INDEX    0x3C8
  77. #define DAC_DATA    0x3C9
  78.  
  79. /*
  80.  * Simplified VGA access instruction macro's
  81.  */
  82.  
  83. #define GET_VGA_BASE    ( (inb(0x03CC) & 0x01) ? 0x03D0 : 0x03B0 )
  84.  
  85. #define Outb_SEQ(index, data)   ( outw( (data) << 8 | (index), SEQ_INDEX) )
  86. #define Inb_SEQ(index)          ( outb(index, SEQ_INDEX) , inb(SEQ_DATA) )
  87.  
  88. #define Outb_CRTC(index, data)  ( outw( (data) << 8 | (index), CRTC_INDEX) )
  89. #define Inb_CRTC(index)         ( outb(index, CRTC_INDEX) , inb(CRTC_DATA) )
  90.  
  91. #define Outb_GR_CTL(index, data) ( outw( (data) << 8 | (index), GR_CTL_INDEX) )
  92. #define Inb_GR_CTL(index)        ( outb(index, GR_CTL_INDEX) , inb(GR_CTL_DATA) )
  93.  
  94. #define OutRGB_DAC(index, data)   ( outb(index, DAC_WR_INDEX) , outb((data >> 16) & 0xFF, DAC_DATA) ,\
  95.                                                               outb((data >> 8 ) & 0xFF, DAC_DATA) ,\
  96.                                                               outb((data      ) & 0xFF, DAC_DATA) )
  97. #define InRGB_DAC(index)          ( outb(index, DAC_RD_INDEX) , ( ( (int) (inb(DAC_DATA) << 8) | inb(DAC_DATA)) << 8) | inb(DAC_DATA) )
  98.  
  99. #define Mask(x)  (1<<(x)) 
  100. #define SetClearBit(indata, bitno, setclear)  ( ((indata) & ~Mask(bitno)) | (((setclear) == 0) ? 0 : Mask(bitno)) )
  101.  
  102. #define Outbit_SEQ(index, bitno, data)   ( Outb_SEQ (index, SetClearBit(Inb_SEQ(index), bitno, data)) )
  103. #define Outbit_CRTC(index, bitno, data)  ( Outb_CRTC (index, SetClearBit(Inb_CRTC(index), bitno, data)) )
  104. #define Outbit_ATR_CTL(index, bitno, data)  ( Outb_ATR_CTL (index, SetClearBit(inb_ATR_CTL(index), bitno, data)) )
  105. #define Outbit_GR_CTL(index, bitno, data)  ( Outb_GR_CTL (index, SetClearBit(Inb_GR_CTL(index), bitno, data)) )
  106.  
  107. #define WRITERGB(index,r,g,b) ( outb((index),DAC_WR_INDEX) , outb((r),DAC_DATA) , outb((g),DAC_DATA) , outb((b),DAC_DATA) )
  108.  
  109.  
  110. void Outb_ATR_CTL (int index, int data);
  111.  
  112. int inb_ATR_CTL (int index);
  113.  
  114. #define SET_PIXELPAN(no)        ( Outb_ATR_CTL(0x13, (inb_ATR_CTL(0x13) & 0xf0) | ((no) & 0x0f)) )
  115.  
  116. #define SCREEN_OFF    ( Outbit_SEQ(0x1, 5, 1) ) /* for maximimum DRAM bandwidth to CPU (DAC does not read) */
  117. #define SCREEN_ON    ( Outbit_SEQ(0x1, 5, 0) )
  118. #define WAIT_VERT_BLK    ( while(inb(0x3c2) & 0x80) )
  119.  
  120. #if DOSYNCRESET
  121. #  define SYNCRESET_SEQ    ( Outbit_SEQ(0, 1, 0) ) /* to avoid memory corruption when changing clocks */
  122. #  define ENDRESET_SEQ    ( Outb_SEQ(0, Inb_SEQ(0) | 0x03) )
  123. #else
  124. #  define SYNCRESET_SEQ 
  125. #  define ENDRESET_SEQ
  126. #endif
  127.  
  128. /* ATI special registers */
  129. #define ATI_EXTREG      0x1CE
  130. #define ATI_GETEXTREG(Index)         ( outb((Index), ATI_EXTREG), inb(ATI_EXTREG+1) )
  131. #define ATI_PUTEXTREG(Index, data)   ( outw((data)<<8|(Index), ATI_EXTREG) )
  132.  
  133. /* OTI special registers */
  134.  
  135. #define OTI_INDEX       0x3DE             /* Oak extended index register */
  136. #define OTI_R_W         OTI_INDEX+1       /* Oak extended r/w register */
  137. #define OTI87_CLOCK     0x6               /* r/w Selects from 16 clocks */
  138. #define OTI_CRT_CNTL    0xC               /* Oak CRT COntrol Register */
  139. #define OTI_MISC        0xD               /* Oak Misc register */
  140. #define Outb_OTI(index, data)  ( outw( (data) << 8 | (index), OTI_INDEX) )
  141. #define Inb_OTI(index)         ( outb(index, OTI_INDEX) , inb(OTI_R_W) )
  142. #define Outbit_OTI(index, bitno, data)  ( Outb_OTI (index, SetClearBit(Inb_OTI(index), bitno, data)) )
  143.  
  144.  
  145. /*****************************************************************************************************************************/
  146. void get_VGA_io_perm(int chipset);
  147.  
  148. #ifndef DOS
  149. #define Renounce_SUID     ( setuid(getuid()) , setgid(getgid()) )
  150. #else
  151. #define Renounce_SUID
  152. #endif
  153.  
  154. /*****************************************************************************************************************************/
  155.  
  156. void unlock(int chipset);
  157.  
  158. void special(int chipset);
  159.  
  160. void interlace(int chipset, t_mode *m);
  161.  
  162. void S3_StartHSText_FontLoad(int pixclock, int do_it);
  163. #define S3_EndHSText_FontLoad()  ( Outbit_CRTC(0x3A, 5, 0) )
  164.           
  165.  
  166. void set_V_timings(int active, int start_sync, int stop_sync, int total);
  167.  
  168. void set_H_timings(int active, int start_sync, int stop_sync, int total);
  169.  
  170. int set_charwidth(int width);
  171. int get_charwidth();
  172.  
  173. /*
  174.  * Some more general functions (less low-level than separate register access)
  175.  */
  176.  
  177. #define Set_VERT_TOTAL(vt)  (Outb_CRTC (0x6, ((vt)-2) & 0xff) , Outbit_CRTC(0x7, 0, ((vt)-2) & 0x100) , Outbit_CRTC(0x7, 5, ((vt)-2) & 0x200))
  178. inline int Get_VERT_TOTAL();
  179.  
  180. #define Set_VRETRACE_START(start)  (Outb_CRTC (0x10, (start) & 0xff) , Outbit_CRTC (0x7, 2, (start) & 0x100) , Outbit_CRTC (0x7, 7, (start) & 0x200) )
  181. inline int Get_VRETRACE_START();
  182. #define Set_VRETRACE_END(end)      (Outb_CRTC (0x11, (Inb_CRTC (0x11) & 0xf0) | ((end) & 0xf)) )
  183. inline int Get_VRETRACE_END();
  184.  
  185. #define Set_VBLANK_START(start)  (Outb_CRTC (0x15, (start) & 0xff) , Outbit_CRTC(0x7, 3, (start) & 0x100) , Outbit_CRTC(0x9, 5, (start) & 0x200) )
  186. #define Set_VBLANK_END(end)      (Outb_CRTC (0x16, (end) & 0xFF) )
  187. inline int Get_VBLANK_START();
  188. inline int Get_VBLANK_END();
  189.  
  190. #define Set_VDISPL_END(vde)  (Outb_CRTC (0x12, ((vde) -1) & 0xff) , Outbit_CRTC(0x7, 1, ((vde) -1) & 0x100) , Outbit_CRTC(0x7, 6, (((vde) -1) & 0x200)))
  191. inline int Get_VERT_DISPL_END();
  192.  
  193. #define Set_MAX_SCANLINE(msl)  (Outb_CRTC (0x9, (Inb_CRTC (0x9) & 0xe0) | (((msl)-1) & 0x1f)))
  194. inline int Get_MAX_SCANLINE();
  195.  
  196. #define Set_CURSOR_START(start)  (Outb_CRTC (0x0A,  (Inb_CRTC(0x0a) & 0xe0) | ((start) & 0x1f) ))
  197. #define Set_CURSOR_END(end)      (Outb_CRTC (0x0B,  (Inb_CRTC(0x0b) & 0xe0) | ( (end)  & 0x1f) ))
  198.  
  199. #define Set_HOR_TOTAL(htot)  (Outb_CRTC(0, (htot) - 5))
  200. inline int Get_HOR_TOTAL();
  201.  
  202. #define Set_HOR_DISPL_END(hend)  (Outb_CRTC(1, (hend) - 1))
  203. inline int Get_HOR_DISPL_END();
  204.  
  205. #define Set_HSYNC_START(start)  (Outb_CRTC(4, start))
  206. #define Set_HSYNC_END(end)  (Outb_CRTC(5, (Inb_CRTC(5) & 0xe0) | ((end) & 0x1f)))
  207. inline int Get_HSYNC_START();
  208. inline int Get_HSYNC_END();
  209.  
  210. #define Set_HBLANK_START(start)  (Outb_CRTC(2, (start) - 1))
  211. #define Set_HBLANK_END(end)  (Outb_CRTC(3, (Inb_CRTC(3) & 0xe0) | (((end) -1) & 0x1f)) , Outbit_CRTC(5, 7, ((end) -1) & 0x20))
  212. inline int Get_HBLANK_START();
  213. inline int Get_HBLANK_END();
  214.  
  215. #define Set_HSYNC_POLARITY(hpol)  (outb((inb(VGA_MISC_R) & 0xBF) | (((hpol) == NEG) ? 0x40 : 0x00) , VGA_MISC_W))
  216. inline bool Get_HSYNC_POLARITY();
  217. #define Set_VSYNC_POLARITY(vpol)  (outb((inb(VGA_MISC_R) & 0x7F) | (((vpol) == NEG) ? 0x80 : 0x00) , VGA_MISC_W))
  218. inline bool Get_VSYNC_POLARITY();
  219.  
  220. #define Set_LOG_SCREEN_WIDTH(width)  (Outb_CRTC(0x13, (width)/2))
  221. #define Get_LOG_SCREEN_WIDTH  ((int)Inb_CRTC(0x13)*2)
  222.  
  223. #define Set_Textmode   (Outb_GR_CTL(6,Inb_GR_CTL(6) & 0xFE) , Outb_ATR_CTL(16,inb_ATR_CTL(16) & 0xFE))
  224. #define Set_Graphmode  (Outb_GR_CTL(6,Inb_GR_CTL(6) | 0x01) , Outb_ATR_CTL(16,inb_ATR_CTL(16) | 0x01))
  225.  
  226. inline int Get_TX_GR_Mode();
  227.  
  228. #define Set_Underline_location(line)  (Outb_CRTC(0x14, line))
  229.  
  230. #endif
  231.  
  232.